var tableArray = [],
  api1 = {},
  layuip={},
  inspectionSheet1;
!(function () {
  layui.use(['table', 'admin', 'laypage', 'jquery', 'laytpl', 'tree', 'form', 'api', 'treeSelect','laydate','utill'], function () {
    var table = layui.table,
            admin = layui.admin,
            laypage = layui.laypage,
            setter = layui.setter,
            utill = layui.utill,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            tree = layui.tree,
            treeSelect = layui.treeSelect,
            api = layui.api,
            laydate = layui.laydate,
            form = layui.form;
    inspectionSheet;
        layuip =layui
    table.on("toolbar(LAY-table-3)", function (obj) {
    });
    table.on("checkbox(inspectionSheet)", function (obj) {
      tableArray = table.checkStatus("#inspectionSheet").data; // 获取勾选数据
    });

    // 日历控件
    laydate.render({
      elem: "#time" //指定元素
    });
    table.on("tool(inspectionSheet)", function (obj) {
      //tcReqId
      if (obj.data.fil05 == 2 || obj.data.fil05 == 1 || obj.data.fil05 == 7) {
        $(this).attr("lay-href", `patrol/popup/create_work#?id=${obj.data.tcReqId}`);
      } else if (obj.data.fil05 == 9 || obj.data.fil05 == 8) {
        $(this).attr("lay-href", `patrol/popup/keep#?id=${obj.data.tcReqId}`);
      }

    });

    // 高查弹窗关闭
    $(".close").on("click", function () {
      $(".boxQuery").css("display", "none");
    });

    // 高查清空
    $(".reset").on("click", function () {
      $(this)
        .parent()
        .prev()
        .find("input")
        .val("")
        .parents("ul")
        .find("select")
        .val("");
    });
    // 高查查询
    $(".sure").on("click", function () {
      let params = {};
      let azp02 = $(".boxQuery")
        .find("input")
        .eq(0)
        .val(); // 公司
      let tc_req_name = $(".boxQuery")
        .find("input")
        .eq(1)
        .val(); // 工单名称
      let fil01 = $(".boxQuery")
        .find("input")
        .eq(2)
        .val(); // 工单编号
      let tc_plan_frequency = $(".boxQuery")
        .find("select")
        .val(); // 巡检计划
      let gen02 = $(".boxQuery")
        .find("input")
        .eq(3)
        .val(); // 巡检人
      let fil12 = $(".boxQuery")
        .find("input")
        .eq(4)
        .val(); // 巡检时间
      let fil07 = $(".boxQuery")
        .find("input")
        .eq(5)
        .val(); // 位置范围
      let tc_detail_fia01a = $(".boxQuery")
        .find("input")
        .eq(6)
        .val(); // 设备编号
      let fil05 = $(".boxQuery")
        .find(".fil05")
        .val(); // 工单状态

      if (azp02) params["azp02"] = azp02;
      if (tc_req_name) params["tc_req_name"] = tc_req_name;
      if (fil01) params["fil01"] = fil01;
      if (tc_plan_frequency) params["tc_plan_frequency"] = tc_plan_frequency;
      if (gen02) params["gen02"] = gen02;
      if (fil12) params["fil12"] = fil12;
      if (fil07) params["fil07"] = fil07;
      if (tc_detail_fia01a) params["tc_detail_fia01a"] = tc_detail_fia01a;
      if (fil05) params["fil05"] = fil05;
      utill.columnCustom('#inspectionSheet', "FilFileXJAndBYVO", {
        url: api.host + "/order/selectListByParam.json",
        where: {
          azp02: azp02,
          tc_req_name: tc_req_name,
          fil01: fil01,
          tc_plan_frequency: tc_plan_frequency,
          gen02: gen02,
          fil12: fil12,
          fil07: fil07,
          tc_detail_fia01: tc_detail_fia01a,
          fil05: fil05
        }, templet: _TPL
      });
      reload(inspectionSheet, params);
      $(".boxQuery").css("display", "none");
    });

    // 高查
    $(".search").on("click", function () {
      $(".boxQuery").css("display", "block");
    });

    // 创建工单
    $(".btn3").on("click", function () {
      $(this).attr("lay-href", "patrol/popup/update_work");
    });

    // 转单
    $(".btn2").click(function () {
      tableArray = table.checkStatus("#inspectionSheet").data;
      if (tableArray.length == 0) return layer.msg("请选择一条数据");
      if (tableArray.length > 1) return layer.msg("只能操作一条数据");
       layer.open({
        id:'layui-layer4',
        type: 2,
        title: false,
        area: ["662px", "536px"],
        fixed: true,
        shadeClose: false,
        closeBtn: 0,
        content: ["../src/views/patrol/popup/changeOrder.html", "no"]
    });
     // layerOpen("../src/views/patrol/popup/changeOrder.html");
    });

    var _TPL = {
      fil05: function (d) {
        if (d.fil05 == 1) {
          return "<span>未开始</span>";
        } else if (d.fil05 == 2) {
          return "<span style='color:blue'>待执行</span>";
        } else if (d.fil05 == 7) {
          return "<span style='color:red'>超时</span>";
        } else if (d.fil05 == 8) {
          return "<span style='color:orange'>超时完成</span>";
        }
        else if (d.fil05 == 9) {
          return "<span style='color:green'>已完成</span>";
        }
      },
      tcReqIsunpln: function (d) {
        if (d.tcReqIsunpln == 0) {
          return "<span>是</span>";
        } else if (d.tcReqIsunpln == 1) {
          return "<span>否</span>";
        }
      }
    };
    // 列定制
    utill.columnCustom('#inspectionSheet', "FilFileXJAndBYVO", {
      url: api.host + "/order/selectListByParam.json",
      cellMinWidth: 120,
      templet: _TPL,
    });

    //是否隐藏转单按钮
    utill.showAndHide('.btn2', 'PollingOrderController:IgiveOrder');
    utill.showAndHide('.btn3', 'PollingOrderController:insertPollingOrder');
    utill.showAndHide('.btn1', 'PollingOrderController:submitXJ');


    var arrs = [];
    table.on("checkbox(inspectionSheet)", function (obj) {
      api1 = api;
    });

    // 批量删除
    $(".btn1").click(function () {
      var arrs_llps = [];
      var checkStatus = table.checkStatus('#inspectionSheet');

      if (checkStatus.data.length == 0) {
        layer.msg('请至少选择一条要删除的数据', { icon: 2 });
        return;
      }
      for (var i = 0; i < checkStatus.data.length; i++) {
        arrs_llps.push(checkStatus.data[i].tcReqId);
      }

      var obj = {
        "tcReqId": arrs_llps
      }
      layer.confirm('真的删除吗？', function (index) {
        admin.req({
          type: 'post',
          dataType: 'json',
          contentType: 'application/json',
          url: api.host + api.delFilFilexj_llp,
          data: JSON.stringify(obj),
          success: function (data) {
            layer.msg(data.message);
            layui.table.reload('#inspectionSheet'); //重载表格  
            //layer.close(index); //执行关闭 
          }
        });
      })
      // 请求
     
    });
  });
  var href = '[data-jump="patrol/cash"]';
  sessionStorage.setItem('layui-this', JSON.stringify(href));
})();